<?php

class Default_Model_Item extends Zend_Db_Table_Abstract
{
    protected $_name = 'item';
    public function getAllData(){
        $query = $this->select()
                        ->from($this->_name, array('itemId','itemName','itemCost','itemFlag'))
                        ->order("itemId ASC");
        return $this->fetchAll($query);
    }
    public function getGameData($gameId){
        $query = $this->select()
                        ->from($this->_name, array('itemId','itemName','itemCost','itemFlag'))
                        ->where("gameID = ?", $gameId)
                        ->order("itemId ASC");
        return $this->fetchAll($query);
    }
    public function getDataByItemId($itemId, $gameId){
    	$query = $this->select()
                        ->from($this->_name, array('itemId','itemName','itemCost','itemFlag', 'gameId'))
                        ->where('itemId = ?',$itemId)
                        ->where('gameId = ?',$gameId);
        return $this->fetchRow($query);
    }
    public function addData($itemId, $itemName, $itemCost, $itemFlag, $gameId){
    	$data = array('itemId' => $itemId, 'itemName' => $itemName, 'itemCost' => $itemCost, 'itemFlag' => $itemFlag, 'gameId' => $gameId, 'createDate' => date("Y-m-d H:i:s"));
        return $this->insert($data);
    }
    public function deleteData($itemId, $gameId){
        $this->delete('itemId = "' . $itemId.'" AND gameId = "' . $gameId . '"');
    }
    public function updateData($itemId, $itemName, $itemCost, $itemFlag, $gameId){
    	$data = array('itemName' => $itemName, 'itemCost' => $itemCost, 'itemFlag' => $itemFlag);
        return $this->update($data, 'itemId = "' . $itemId.'" AND gameId = "' . $gameId . '"');
    }

}